package com.smallchill.common.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.quartz.SchedulerException;

import com.smallchill.common.job.JobTask;
import com.smallchill.core.utils.Prop;
import com.smallchill.core.utils.QuartzKit;

public class QuartzListener implements ServletContextListener {
	
	private static String jobTime;
	private static boolean doJob;
	
	static {
		Prop prop = Prop.init("config.properties");
		doJob = prop.getBoolean("doJob", false);
		jobTime = prop.get("jobTime", "0 0/5 * * * ?");
	}
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		try {
			if (doJob) {
				QuartzKit.addJob("job1", "trigger1", JobTask.class, jobTime);
			}
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}
	
}